function mappingAFI

% FUNCTION MAPPINGAFI

figure
BrightFig = imread('C:\Data\Taro\images\081001\bf2.TIF');
imagesc(BrightFig)

StimPosition = [409,654];
StimPosition = 3 / 10 * (StimPosition + repmat([1333 -1000],size(StimPosition,1),1));
StimPosition(:,2) = -StimPosition(:,2)';
keyboard;

for m = 1:length(StimPosition(:,1))
    line(StimPosition(m,1),StimPosition(m,2),'Marker','diamond','Color','r')
end

AFI_filepath = {str2mat('C:\Data\Taro\images\081001\m1_9_.qcamraw','C:\Data\Taro\images\081001\m1_9_001.qcamraw',...
    'C:\Data\Taro\images\081001\m1_9_002.qcamraw','C:\Data\Taro\images\081001\m1_9_003.qcamraw',...
    'C:\Data\Taro\images\081001\m1_9_004.qcamraw','C:\Data\Taro\images\081001\m1_9_005.qcamraw',...
    'C:\Data\Taro\images\081001\m1_9_006.qcamraw','C:\Data\Taro\images\081001\m1_9_007.qcamraw',...
    'C:\Data\Taro\images\080922\stim1_008.qcamraw','C:\Data\Taro\images\080922\stim1_009.qcamraw'),...
    };



DiffF = zeros(150,200,length(AFI_filepath));

for k = 1:length(AFI_filepath)
    Prestim = zeros(150,200);
    for i = 1:length(AFI_filepath{k}(:,1))
        for j = 2:11
            Prestim = double(qcammex('getFrames',AFI_filepath{k}(1,:),j))' + Prestim;
        end
    end
    Prestim = Prestim / (i * (j - 1));
    
    clear qcammex
    Poststim = zeros(150,200);
    for i = 1:length(AFI_filepath{k}(:,1))
            Poststim = double(qcammex('getFrames',AFI_filepath{k}(1,:),22))' + Prestim;
    end
    Poststim = Poststim / i;
    
    DiffF(:,:,k) = Poststim ./ Prestim;   
    
end

for m = 1:k
    if mod(m,4) == 1
        figure
    end
    try
        subplot(2,2,mod(m,4))
        imagesc(DiffF(:,:,m))
    catch
        subplot(2,2,4)
        imagesc(DiffF(:,:,m))
    end
end


